A well system (e.g., an oil or gas well for extracting fluid or gas from a subterranean formation) can include various electrical devices in a wellbore. For example, a well system can include a sensor for detecting an environmental characteristic in the wellbore. The electrical devices can be powered by wirelines, generators, batteries, and supercapacitors. For example, an electrical device can be powered by a generator and include a supercapacitor as a back-up energy source. But harsh environmental conditions in the wellbore, such as high temperatures, can cause supercapacitors to fail. Failure of a supercapacitor can cause an associated electrical device to shut down or otherwise operate improperly.